package basic;

/**
 * @Author: 海琳琦
 * @Date: 2021/8/30 20:04
 */
public class Title14 {
    public static void main(String[] args) {
        String[] strs = {"ab","a"};
        longestCommonPrefix(strs);
    }

    private static String longestCommonPrefix(String[] strs) {
        if(strs.length==1){
            return strs[0];
        }
        String s = strs[0];
        for (int i = 0; i < s.length(); i++) {
            for (int j = 1; j < strs.length; j++) {
                if(i>=strs[j].length()||s.charAt(i)!=strs[j].charAt(i)){
                    return s.substring(0, i);
                }
            }
        }
        return s;

    }
}
